package com.lsht.web.controller.siwei;

import com.github.pagehelper.PageInfo;
import com.lsht.common.bo.IdListAcceptBo;
import com.lsht.common.core.controller.BaseController;
import com.lsht.common.core.domain.AjaxResult;
import com.lsht.system.domain.siwei.SiweiJwd;
import com.lsht.system.service.siwei.SiweiJwdService;
import com.lsht.system.util.NullUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zyc
 * @date 2024/11/17 14:08
 */
@RestController
@RequestMapping("/siwei/jwd")
@Api(value = "SiweiJwd", description = "区域自动回显", tags = "区域自动回显")
public class SiweiJwdController extends BaseController {
    @Autowired
    private SiweiJwdService siweiJwdService;

    /**
     * 新增区域自动回显
     */
    @PostMapping(ADD_FUNCTION_URL)
    @ApiOperation(value = ADD_FUNCTION, httpMethod = "POST", response = SiweiJwd.class, tags = "区域自动回显")
    public AjaxResult genAdd(@RequestBody SiweiJwd siweiJwd) {
        return toAjax(siweiJwdService.genAdd(siweiJwd));
    }

    /**
     * 删除区域自动回显
     */
    @PostMapping(DELETE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = DELETE_BY_ID_FUNCTION, httpMethod = "POST", response = AjaxResult.class, tags = "区域自动回显")
    public AjaxResult genDeleteById(@RequestBody IdListAcceptBo idListAcceptBo) {
        List<String> idList = idListAcceptBo.getIdList();
        if (CollectionUtils.isNotEmpty(idList)) {
            return toAjax(siweiJwdService.genDeleteById(idList));
        }
        return AjaxResult.error();
    }

    /**
     * 修改区域自动回显
     */
    @PostMapping(UPDATE_BY_ID_FUNCTION_URL)
    @ApiOperation(value = UPDATE_BY_ID_FUNCTION, httpMethod = "POST", response = AjaxResult.class, tags = "区域自动回显")
    public AjaxResult genUpdateById(@RequestBody SiweiJwd siweiJwd) {
        return toAjax(siweiJwdService.genUpdateById(siweiJwd));
    }

    /**
     * 查询区域自动回显列表
     */
    @PostMapping(QUERY_LIST_FUNCTION_URL)
    @ApiOperation(value = QUERY_LIST_FUNCTION, httpMethod = "POST", response = SiweiJwd.class, tags = "区域自动回显")
    public AjaxResult genQueryList(@RequestBody SiweiJwd siweiJwd) {
        startPage();
        List<SiweiJwd> list = siweiJwdService.genQueryList(siweiJwd);
        return AjaxResult.success(new PageInfo<>(list));
    }


    /**
     * 根据经纬度返回区域位置名称
     */
    @PostMapping("getAreaNameByPosition")
    @ApiOperation(value = "根据经纬度返回区域位置名称", httpMethod = "POST", response = SiweiJwd.class, tags = "区域自动回显")
    public AjaxResult getAreaNameByPosition(@RequestBody SiweiJwd siweiJwd) {
        if (NullUtil.isNotEmpty(siweiJwd.getLan()) && NullUtil.isNotEmpty(siweiJwd.getLat())) {
            return AjaxResult.success(siweiJwdService.getAreaNameByPosition(siweiJwd));
        }

        return AjaxResult.error("经纬度不能为空");

    }
}
